package My.Nhom2.ServiceSearch;

import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.widget.LinearLayout.LayoutParams;

public class GoogleMapOnlineActivity extends MapActivity implements
		OnClickListener {
	/** The mapView. */
	MapView mapView;

	/** The MapController. */
	MapController mc;

	/** The ZoomLayout. */
	LinearLayout zoomLayout;

	/** The GeoPoint. */
	GeoPoint p;

	/** The button back */
	Button bt_back;

	/** The item result service. */
	private DataService item;
	
	private OverlayItem  mosqueItem;
	
	private List<Overlay> mapOverlays;

	@SuppressWarnings("deprecation")
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.googlemapsearch);

		item = ServiceSearchActivity.node;

		mapView = (MapView) findViewById(R.id.myMap);
		zoomLayout = (LinearLayout) findViewById(R.id.zoom);

		bt_back = (Button) findViewById(R.id.bt_onlineback);
		bt_back.setOnClickListener(this);
		View zoomView = mapView.getZoomControls();
		zoomLayout.addView(zoomView, new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		mapView.setBuiltInZoomControls(true);
		mapView.setTraffic(true);

		double latiTude = Double.parseDouble(item.getViDo());
		double longiTude = Double.parseDouble(item.getKinhDo());
		p = new GeoPoint((int) (latiTude * 1E6), (int) (longiTude * 1E6));
		
		
		mapOverlays = mapView.getOverlays();
		Drawable drawable = this.getResources().getDrawable(R.drawable.marker);
		CustomItemizedOverlay itemizedoverlay = new CustomItemizedOverlay(drawable);
		mosqueItem = new OverlayItem( p, "Zitouna Mosque", "Kairouan");
		itemizedoverlay.addOverlay(mosqueItem);
		mapOverlays.add(itemizedoverlay);
		
		mc = mapView.getController();
		mc.animateTo(p);
		mc.setZoom(17);
		mapView.invalidate();
	}
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v.getId() == R.id.bt_onlineback) {
			Intent intent = new Intent();
			setResult(RESULT_OK, intent);
			finish();
		}
	}
	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

}
